package com.yunlin.utils;

/**
 * Created by lixiaodaoaaa on 2017/8/16.
 */

public class ConvertUtils{
    
    public static int byteToInt(byte b){
        return b & 0xFF;
    }
    
    public static String bytesToStringData(byte[] bytes){
        StringBuilder dataBuilder=new StringBuilder();
        if (bytes != null && bytes.length > 0) {
            for (int i=0; i < bytes.length; i++) {
                String hexValue=FormatUtils.intValueTo2HexString(ConvertUtils.byteToInt(bytes[i]));
                dataBuilder.append(hexValue);
            }
        }
        return dataBuilder.toString();
    }
    
    
    /**
     * 参考：http://ascii.911cha.com
     * 将ascii值转为hex16进制形式表现
     *
     * @return
     */
    public static String asciiStrToHexStr(String assicValue){
        return FormatUtils.intValueTo2HexString(Integer.valueOf(assicValue));
    }
    
    
    public static byte int2OneByte(int num){
        return (byte) (num & 0x000000ff);
    }
}
